package com.globallogic.socialnetwork.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;


/**
 * The persistent class for the groups database table.
 * 
 */
@Entity
@Table(name="groups")
public class Group implements Serializable {
        private static final long serialVersionUID = 1L;

        @Id
        @GeneratedValue(strategy=GenerationType.AUTO)
        private int idGroup;

        private String nameGroup;

        //bi-directional many-to-many association to User
        @ManyToMany(mappedBy="groups",fetch=FetchType.LAZY)
        //@LazyCollection(LazyCollectionOption.FALSE)
        private List<User> users;

    public Group() {
    }
    public Group(String nameGroup) {
        this.nameGroup=nameGroup;
    }
        public int getIdGroup() {
                return this.idGroup;
        }

        public void setIdGroup(int idGroup) {
                this.idGroup = idGroup;
        }

        public String getNameGroup() {
                return this.nameGroup;
        }

        public void setNameGroup(String nameGroup) {
                this.nameGroup = nameGroup;
        }

        public List<User> getUsers() {
                return this.users;
        }

        public void setUsers(List<User> users) {
                this.users = users;
        }
        @Override
        public String toString() {
                return "Group [nameGroup=" + nameGroup + "]";
        }
        @Override
        public int hashCode() {
                return new HashCodeBuilder().append(idGroup).append(nameGroup).toHashCode();
        }

        @Override
        public boolean equals(Object obj) {
                if (this == obj)
                        return true;
                if (obj == null)
                        return false;
                if (getClass() != obj.getClass())
                        return false;
                Group other = (Group) obj;
                return new EqualsBuilder().append(idGroup,other.idGroup).append(nameGroup,other.nameGroup).isEquals();
        }
}